package main

import "fmt"

func fib(n int, fChan chan int) {
	// 第一个数字为 0
	x, y := 0, 1

	for i := 0; i < n; i++ {

		x, y = x+y, x
		fChan <- x

	}

	close(fChan)

}

func main() {

	fChan := make(chan int, 2)
	go fib(cap(fChan), fChan)

	for n := range fChan {
		fmt.Println(n)
	}

	_, ok := <-fChan
	if !ok {
		fmt.Println("channel already closed!")
		return
	}

}
